export default {
    data() {
        return {
            monthDate: [
                // '1月','2月','3月','4月',"5月",'6月','1月','2月','3月','4月',"5月",'6月',
                // '1月','2月','3月','4月',"5月",'6月','1月','2月','3月','4月',"5月",'6月',
                // '1月','2月','3月','4月',"5月",'6月','1月','2月','3月','4月',"5月",'6月',
                "2022-10",
                "2022-11",
                "2022-12",
                "2023-01",
                "2023-02",
                "2023-03",
                "2023-04",
                "2023-05",
                "2023-06",
                "2023-07",
                "2023-08",
                "2023-09"
            ],
        }
    },
    methods: {
        initChart(dayList,text, color, data, legend, chart, o_text) {
            // console.log(dayList,text, color, data, legend, chart, o_text,"---haha---");
            let myChart = chart;
            let option = {
                title: {
                    text: o_text ? o_text : (text),
                },
                tooltip: {
                    // trigger: 'axis'
                    formatter: function (val) {
                        return `${val.name}<br/>${val.marker}${text} ${val.value}`;
                    },
                },
                legend: {
                    data: legend,
                    width: 30,
                    right: 0
                },
                xAxis: {
                    type: "category",
                    data: dayList, //dayList,
                    axisLabel: {
                        interval: 0  // 显示全部刻度
                    }
                },
                yAxis: {
                    type: "value",
                    axisLabel: {
                        formatter: "{value}",
                    },
                },
                series: [
                    {
                        data: data[0],
                        type: "line",
                        color: color[0],
                        lineStyle: {
                            normal: {
                                color: color[0],
                            },
                        },
                        name: legend[0],
                    },
                    {
                        data: data[1],
                        type: "line",
                        color: color[1],
                        lineStyle: {
                            normal: {
                                color: color[1],
                            },
                        },
                        name: legend[1],
                    },
                ],
            };
            myChart.setOption(option);
            window.addEventListener("resize", () => {
                this.$nextTick(() => {
                    myChart.resize();
                })
            });
        },
        initYearChart(monthList,text, color, data, legend, chart, o_text) {
            // console.log(monthList,text, color, data, legend, chart, o_text,"---xixi---");
            let myChart = chart;
            let option = {
                title: {
                    text: o_text ? o_text : (text),
                },
                tooltip: {
                    // trigger: 'axis'
                    formatter: function (val) {
                        return `${val.name}<br/>${val.marker}${text} ${val.value}`;
                    },
                },
                legend: {
                    data: legend,
                    width: 30,
                    right: 0
                },
                xAxis: {
                    type: "category",
                    data: monthList,//monthList, //dayList,
                    axisLabel: {
                        interval: 0  // 显示全部刻度
                    }
                },
                yAxis: {
                    type: "value",
                    axisLabel: {
                        formatter: "{value}",
                    },
                },
                series: [
                    {
                        data: data[0],
                        type: "line",
                        color: color[0],
                        lineStyle: {
                            normal: {
                                color: color[0],
                            },
                        },
                        name: legend[0],
                    },
                    {
                        data: data[1],
                        type: "line",
                        color: color[1],
                        lineStyle: {
                            normal: {
                                color: color[1],
                            },
                        },
                        name: legend[1],
                    },
                    {
                        data: data[2],
                        type: "line",
                        color: color[2],
                        lineStyle: {
                            normal: {
                                color: color[2],
                            },
                        },
                        name: legend[2],
                    },
                ],
            };
            myChart.setOption(option);
            window.addEventListener("resize", () => {
                this.$nextTick(() => {
                    myChart.resize();
                })
            });
        },
        initMonthChart(monthList,text, color, data, legend, chart, o_text) {
            // console.log(monthList,text, color, data, legend, chart, o_text,"---xixi---");
            let myChart = chart;
            let option = {
                title: {
                    text: o_text ? o_text : (text),
                },
                tooltip: {
                    // trigger: 'axis'
                    formatter: function (val) {
                        return `${val.name}<br/>${val.marker}${text} ${val.value}`;
                    },
                },
                legend: {
                    data: legend,
                    width: 30,
                    right: 0
                },
                xAxis: {
                    type: "category",
                    data: monthList,//monthList, //dayList,
                    axisLabel: {
                        interval: 0  // 显示全部刻度
                    }
                },
                yAxis: {
                    type: "value",
                    axisLabel: {
                        formatter: "{value}",
                    },
                },
                series: [
                    {
                        data: data[0],
                        type: "line",
                        color: color[0],
                        lineStyle: {
                            normal: {
                                color: color[0],
                            },
                        },
                        name: legend[0],
                    },
                ],
            };
            myChart.setOption(option);
            window.addEventListener("resize", () => {
                this.$nextTick(() => {
                    myChart.resize();
                })
            });
        },
    }
}
